package com.mr.example3.friend;

import java.io.IOException;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

/*
 * 1.输入数据：（用户-用户	好友）
 * 		(A-E	B)，(A-F	B),(E-F	B)
 * 		(A-E	C)
 *
 * 2.输出数据：（用户-用户:好友，好友）
 * 		(A-E:B,C)，(A-F:B),(E-F:B)
 */

public class Example3Reducer2 extends Reducer<Text, Text, Text, NullWritable>{


	@Override
	protected void reduce(Text key, Iterable<Text> values, Reducer<Text, Text, Text, NullWritable>.Context context)
			throws IOException, InterruptedException {

		StringBuffer sb = new StringBuffer();

		for (Text value : values) {

			// 拼接字符串
			sb.append(value.toString() + ",");

		}

		context.write(new Text(key + ":" +sb.deleteCharAt(sb.length() - 1).toString()), NullWritable.get());

	}

}
